/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package loja.bean;

import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import loja.entity.Cliente;

/**
 *
 * @author eqalmeida
 */
@ManagedBean
@ViewScoped
public class ClienteBean {
    
    private DataModel<Cliente> clientes;
    private Cliente cliente;
    private int action = 0;
    
    @PersistenceContext
    private EntityManager em;
    
    public void editar(){
	cliente = (Cliente) clientes.getRowData();
    }

    public int getAction() {
	return action;
    }

    public void setAction(int action) {
	this.action = action;
    }

    public Cliente getCliente() {
	return cliente;
    }

    public void setCliente(Cliente cliente) {
	this.cliente = cliente;
    }

    public DataModel<Cliente> getClientes() {
	clientes = new ListDataModel<Cliente>( em.createQuery("SELECT c FROM Cliente c").getResultList() );
	
	return clientes;
    }

    public void setClientes(DataModel<Cliente> clientes) {
	this.clientes = clientes;
    }
  
    

    /**
     * Creates a new instance of ClienteBean
     */
    public ClienteBean() {
    }
}
